@import '../../styles/var.scss';
@import '../../styles/mixins.scss';

.m-media {
  position: relative;
  background-color: #f5f5f5;
  overflow: hidden;
  border-radius: 8px;

  &-image {
    width: 100%;
    height: 100%;
    display: block;
  }

  &-video {
    width: 100%;
    height: 100%;
    background-color: #000;

    &-icon {
      @include absolute-center;
      color: #fff;
      background-color: rgba(0, 0, 0, 0.5);
      border-radius: 50%;
      padding: 8px;
      pointer-events: none;
      z-index: 3;
    }

    // 视频封面优化
    &::after {
      content: '';
      position: absolute;
      bottom: 8px;
      right: 8px;
      width: 24px;
      height: 24px;
      background: rgba(0, 0, 0, 0.6);
      border-radius: 4px;
      z-index: 2;
    }

    // 视频占位图
    &-placeholder {
      position: absolute;
      top: 0;
      left: 0;
      width: 100%;
      height: 100%;
      display: flex;
      align-items: center;
      justify-content: center;
      background-color: #e8e8e8;
      z-index: 1;
    }
  }

  // 视频标识图标
  &-video-badge {
    position: absolute;
    bottom: 8px;
    right: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    background: rgba(0, 0, 0, 0.6);
    border-radius: 4px;
    color: #fff;
    font-size: 12px;
    z-index: 3;
    pointer-events: none;
  }

  // 占位图
  &-placeholder {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
  }

  // 骨架屏加载状态
  &-skeleton {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 37%, #f0f0f0 63%);
    background-size: 400% 100%;
    animation: skeleton-loading 1.4s ease infinite;
    z-index: 1;
  }

  @keyframes skeleton-loading {
    0% {
      background-position: 100% 50%;
    }
    100% {
      background-position: 0 50%;
    }
  }

  // 加载状态
  &-loading {
    .m-media-image {
      opacity: 0;
      transition: opacity 0.3s ease;
    }
  }

  &-loading .m-media-image[data-loaded='true'] {
    opacity: 1;
  }

  // 错误状态
  &-error {
    background-color: #f5f5f5;
  }

  &-error-placeholder {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: #f5f5f5;
    z-index: 2;
  }
}
